package br.com.guiav6.sisguia.dao.hibernate;

import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;

import br.com.guiav6.sisguia.dao.CepDao;
import br.com.guiav6.sisguia.entity.Cep;
import br.com.guiav6.sisguia.repository.hibernate.AbstractDaoHibernate;

@Repository("cepDao")
public class CepDaoHibernate extends AbstractDaoHibernate<Long, Cep> implements CepDao {

	@Override
	public Cep findByNuCep(String nuCep) {
		TypedQuery<Cep> q = getEntityManager().createQuery("from Cep where nuCep = :nuCep", Cep.class);
		q.setParameter("nuCep", nuCep);
		try{
			return q.getSingleResult();
		}catch (NoResultException nre) {
			return null;
		}
	}

}